﻿@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenDataGrid
    Data="@employees"
    TItem="Employee"
    AllowFiltering=true
    ColumnWidth="300px"
    AllowColumnPicking="true"
    PickedColumnsChanged="@PickedColumnsChanged"
    ColumnsPickerAllowFiltering="true"
>
    <Columns>
        <RadzenDataGridColumn
            Property=@nameof(Employee.EmployeeID)
            Title="ID"
            Width="80px"
            TextAlign="TextAlign.Center"
            Frozen="true" />
        <RadzenDataGridColumn Title="Photo" Sortable="false" Width="200px" Pickable="false">
            <Template Context="data">
                <RadzenImage Path="@data.Photo" class="rz-gravatar" AlternateText="@(data.FirstName + " " + data.LastName)" />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn Property=@nameof(Employee.FirstName) Title="First Name" />
        <RadzenDataGridColumn Property=@nameof(Employee.LastName) Title="Last Name" Width="150px"/>
        <RadzenDataGridColumn Property=@nameof(Employee.Title) Title="Title" />
        <RadzenDataGridColumn Property=@nameof(Employee.TitleOfCourtesy) Title="Title Of Courtesy" />
        <RadzenDataGridColumn Property=@nameof(Employee.BirthDate) Title="Birth Date" FormatString="{0:d}" />
        <RadzenDataGridColumn Property=@nameof(Employee.HireDate) Title="Hire Date" FormatString="{0:d}" />
        <RadzenDataGridColumn Property=@nameof(Employee.Address) Title="Address" />
        <RadzenDataGridColumn Property=@nameof(Employee.City) Title="City" />
        <RadzenDataGridColumn Property=@nameof(Employee.Region) Title="Region" />
        <RadzenDataGridColumn Property=@nameof(Employee.PostalCode) Title="Postal Code" />
        <RadzenDataGridColumn Property=@nameof(Employee.Country) Title="Country" />
        <RadzenDataGridColumn Property=@nameof(Employee.HomePhone) Title="Home Phone" />
        <RadzenDataGridColumn Property=@nameof(Employee.Extension) Title="Extension" ColumnPickerTitle="Phone Number Extension" />
        <RadzenDataGridColumn Property=@nameof(Employee.Notes) Title="Notes" />
    </Columns>
</RadzenDataGrid>
<EventConsole @ref=@console />

@code {
    IEnumerable<Employee> employees;
    EventConsole console;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        employees = dbContext.Employees;
    }

    /// <summary>
    /// Only used to print the changes to the console.
    /// </summary>
    void PickedColumnsChanged(DataGridPickedColumnsChangedEventArgs<Employee> args)
    {
        console.Log($"Picked columns: {string.Join(", ", args.Columns.Select(c => c.Title))}");
    }
}